var gulp = require('gulp');
var coffee = require('gulp-coffee');
var jade = require('gulp-jade');
var plumber = require('gulp-plumber');
var beep = require('beepbeep');

function errorHandler(err) {
    beep(2);
    console.error(err.toString());
}

gulp.task('server', [], function () {
    gulp.src('src/**/*.coffee')
        .pipe(plumber({errorHandler: errorHandler}))
        .pipe(coffee())
        .pipe(gulp.dest('dist/'));
    gulp.src('src/**/*.js')
        .pipe(plumber({errorHandler: errorHandler}))
        .pipe(gulp.dest('dist/'));
});

gulp.task('jade', [], function () {
    gulp.src('src/jade/**.jade')
        .pipe(gulp.dest('dist/jade/'));
});

gulp.task('config', [], function () {
    return gulp.src("config.js").pipe(gulp.dest('dist/'));
});

gulp.task('static', [], function () {
    return gulp.src("static/**").pipe(gulp.dest('dist/static/'));
});

gulp.task('watch', ['default'], function () {
    gulp.watch('src/**/*.coffee', ['server']);
    gulp.watch('src/jade/**.jade', ['jade']);
    gulp.watch('config.js', ['config']);
    gulp.watch('static/**', ['static']);
});

gulp.task('default', ['server', 'config', 'jade']);